﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;


namespace DrugStorehouseMIS.DAL
{
    public class StockOutHeaderDAL:IStockOutHeaderDAL
    {
        #region IStockOutHeaderDAL 成员

        public IDataReader Select(string StockOutNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_StockOutHeader_Select", new SqlParameter[] { new SqlParameter("@StockOutNum", StockOutNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public DataTable SelectByStatus(string Status)
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockOutHeader_Select_By_Status", new SqlParameter[] { new SqlParameter("@Status", Status) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public DataTable Select(string StockOutNum, string StockOutTypeName, string DepartmentName, string Status)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutNum",StockOutNum),
                    new SqlParameter("@StockOutTypeName",StockOutTypeName),
                    new SqlParameter("@DepartmentName",DepartmentName),  
                    new SqlParameter("@Status",Status)
                };
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockOutHeader_Filter", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Insert(string StockOutNum, string StockOutTypeName, DateTime StockOutDatetime, string DepartmentName, string CreatedBy, string ApprovalBy, string Remark, string Status)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutNum",StockOutNum),
                    new SqlParameter("@StockOutTypeName",StockOutTypeName),
                    new SqlParameter("@StockOutDatetime",StockOutDatetime),
                    new SqlParameter("@DepartmentName",DepartmentName),                
                    new SqlParameter("@CreatedBy",CreatedBy),
                    new SqlParameter("@ApprovalBy",ApprovalBy),                    
                    new SqlParameter("@Remark",Remark),
                    new SqlParameter("@Status",Status)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutHeader_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
          
        }

        public int Update(string StockOutNum, string StockOutTypeName, DateTime StockOutDatetime, string DepartmentName, string CreatedBy, string ApprovalBy, string Remark, string Status)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockOutNum",StockOutNum),
                    new SqlParameter("@StockOutTypeName",StockOutTypeName),
                    new SqlParameter("@StockOutDatetime",StockOutDatetime),
                    new SqlParameter("@DepartmentName",DepartmentName),                
                    new SqlParameter("@CreatedBy",CreatedBy),
                    new SqlParameter("@ApprovalBy",ApprovalBy),                    
                    new SqlParameter("@Remark",Remark),
                    new SqlParameter("@Status",Status)
                };
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutHeader_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(string StockOutNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockOutHeader_Delete", new SqlParameter[] { new SqlParameter("@StockOutNum", StockOutNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        #endregion
    }
}
